﻿using HY.Common;
using HY.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace HY.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //BaseService baseService = new BaseService();
            //baseService.MigrateDatabaseToLatestVersion();
        }
        protected void Application_Error(object sender, EventArgs e)
        {
            //捕获异常
            Exception ex = Server.GetLastError();

            //书写日志
            LogHelper.Error("全局异常处理", ex);
            var baseException = ex.GetBaseException();
            //根据错误跳转自定义错误页面
            if (baseException is HttpException && ((HttpException)baseException).GetHttpCode() == 404)
            {
                Server.ClearError();
                Response.Redirect("~/Home/Error_404");
            }
        }
    }
}
